home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
- Subject: Re: Access carry flag from C
- Date: 20 Feb 96 23:33:40 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.824859220@rscernix>
- References: <Dn1C9z.DGv.0.net@indra.com> <1996Feb1922.17.19.879@koobera.math.uic.edu> <31298D20.41C6@bazis.nl>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <31298D20.41C6@bazis.nl> fkorntne@bazis.nl (Franz Korntner) writes:
-
- >Steve Sullivan <sullivan@indra.com> wrote:
- >> i = j + k;
- >> if (overflowed) ....;
- >
- >Yes there is a method.
- >
- >j+k will overflow when the result exceeds MAXINT
- >
- >Thus: "if (j+k > MAXINT) overflow();" but the operation is undefined
- >if the result overflows, so the expression needs rewriting to make sure
- >this doesn't happen. The result is then "if (j>MAXINT-k) overflow();".
-
- If k is negative, MAXINT-k will overflow :-)
-
- BTW, MAXINT is spelled INT_MAX in C.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-